package mn.more.wits.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import mn.more.wits.client.dto.Payload;
import mn.more.wits.client.exception.WitsSecurityException;

public interface AuthProvider extends RemoteService {

	/**
	 * Utility/Convenience class. Use ExamProvider.App.getInstance() to access
	 * static instance of ExamProviderAsync
	 */
	class App {

		private static AuthProviderAsync ourInstance;

		private App() {}

		public static synchronized AuthProviderAsync getInstance() {
			if (ourInstance == null) {
				ourInstance = (AuthProviderAsync) GWT.create(AuthProvider.class);
				((ServiceDefTarget) ourInstance).setServiceEntryPoint(GWT.getModuleBaseURL() + "rpc/auth");
			}
			return ourInstance;
		}
	}

	/** authenticate the username/password combination on the server-side. */
	Payload authenticate(Payload auth) throws WitsSecurityException;

	/** retrieve the currently in-session authentication model. */
	Payload getAuth();

	/** invalid the currently in-session authentication model, effectively logging out of a session. */
	void invalidate() throws WitsSecurityException;

	/**
	 * allow end-user to change password from UI.  <code>chgpwd</code> represents the encrypted wrapper of the
	 * {@link mn.more.wits.client.dto.ChangePasswordDTO} model.
	 */
	void changePassword(Payload chgpwd) throws WitsSecurityException;
}
